package com.njwb.day15.zqzb.method.review;

import java.lang.reflect.Field;

public class ObjectUtil {
    public static Object copyObject(Object obj) {
        Object returnObject = null ;
        try {
            returnObject = obj.getClass().newInstance();
            Field[] declaredFields = obj.getClass().getDeclaredFields();
            for (Field f:declaredFields) {
                f.setAccessible(true);
                Object value = f.get(obj);
                f.set(returnObject,value);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return returnObject;
    }
}
